﻿using mscook.core.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Linq;
namespace mscook.core.repositories
{
    public class PurchasedThingRepository : Repository<PurchasedThing>,IPurchasedThingRepository
    {
        public IList<PurchasedThing> GetBy(LoginUser loginUser)
        {
            var query = (from x in this.Session.Query<PurchasedThing>() select x)
           .Where(o => o.IsDelete == false
               && o.LoginUser == loginUser);           
            return query.ToList();
        }

        public IList<PurchasedThing> GetBy(LoginUser loginUser, PurchasedCategory category)
        {
            var query = (from x in this.Session.Query<PurchasedThing>() select x)
           .Where(o => o.IsDelete == false
               && o.LoginUser == loginUser
               &&o.PurchasedCategory==category
               );
            return query.ToList();
        }

        public int GetHasPurchased(LoginUser loginUser,PurchasedCategory category)
        {
            var query = (from x in this.Session.Query<PurchasedThing>() select x)
          .Where(o => o.IsDelete == false
              && o.LoginUser == loginUser
              && o.PurchasedCategory == category
              );
            return query.Count();
        }

       

        



    }
}
